/**
 * Created with IntelliJ IDEA.
 * User: duoba
 * Date: 16/2/25
 * Time: 上午10:56
 * To change this template use File | Settings | File Templates.
 */

package com.cake21.uitest.Page;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import com.cake21.uitest.System.Core.Page;

public class CheckOutPage extends Page {
    /*页面元素*/
    @FindBy(id = "IDsubmitorder")
    private WebElement submitOrderBtn;
    @FindBy(name = "ship_time_scope")
    private WebElement shipTimeInput;
    @FindBy(id = "ship_time_scope_list")
    private WebElement shipTimeScopeList;

    /*构造函数*/
    public CheckOutPage(WebDriver driver) {
        this.driver = driver;
    }

    /*选择送货时间*/
    public void selectShipTime() {
        try {
            this.shipTimeInput.click();
            if (shipTimeScopeList.isDisplayed()) {
                List<WebElement> shipTimeList = shipTimeScopeList.findElements(By.className("scope_item"));
            /*选取第一个可选的时间段*/
                shipTimeList.get(0).click();
            } else {
                this.shipTimeInput.click();
                if (shipTimeScopeList.isDisplayed()) {
                    List<WebElement> shipTimeList = shipTimeScopeList.findElements(By.className("scope_item"));
            /*选取第一个可选的时间段*/
                    shipTimeList.get(0).click();
                }
            }
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }

    /*获得送货时间*/
    public String getShipTime() {
        return this.shipTimeInput.getAttribute("value");
    }

    /*点击下单*/
    public void goSubmitOrder() {
        this.submitOrderBtn.click();
    }

}
